package com.zhiwang.planet.ui.my.reward

import android.os.Bundle
import android.text.Editable
import android.util.Log
import com.zhiwang.planet.R
import com.zhiwang.planet.di.component.DaggerUserComponent
import com.zhiwang.planet.di.module.AccountModule
import com.zhiwang.planet.di.module.AutoDisposeModule
import com.zhiwang.planet.mvp.p.ScalarPresenter
import com.zhiwang.planet.ui.BaseActivity
import com.zhiwang.planet.ui.TextWatcherAdapter
import com.zhiwang.planet.widget.SimpleDialogBuilder
import kotlinx.android.synthetic.main.activity_verify_card.*
import javax.inject.Inject

class VerifyCardActivity : BaseActivity() {

    val TAG = "VerifyCardActivity"

    @Inject
    lateinit var presenter: ScalarPresenter

    override fun onSupportNavigateUp(): Boolean {
        onBackPressed()
        return true
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        DaggerUserComponent.builder()
                .appComponent(getAppComponent())
                .accountModule(AccountModule(this))
                .autoDisposeModule(AutoDisposeModule(this))
                .build()
                .inject(this)
        setContentView(R.layout.activity_verify_card)
        setSupportActionBar(toolbar)

        observeTextChangeWithTargetButtonEnableStatus(arrayOf(et_card_number), verify_card_btn)

        verify_card_btn.setOnClickListener {
            presenter.verifyCard(et_card_number.text.toString().trim(), ::showFinalMsg, ::onError)
        }

        et_card_number.addTextChangedListener(object : TextWatcherAdapter() {

            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
                super.beforeTextChanged(s, start, count, after)
                Log.i(TAG, "beforeTextChanged: $s")

            }

            override fun afterTextChanged(s: Editable?) {
                super.afterTextChanged(s)
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                super.onTextChanged(s, start, before, count)
            }
        })
    }


    fun showFinalMsg(msg: String) {
        et_result.setText(msg)
//        SimpleDialogBuilder()
//                .title("")
//                .content(msg)
//                .buttonText("我知道了")
//                .build(this)
//                .show()

    }


}
